package prosjekt;

import javax.swing.*;
import java.io.UnsupportedEncodingException;
import java.net.*;

/**
 * A JLabel containing a map from Google's static map service
 * @author Henning
 *
 */
@SuppressWarnings("serial")
class GMapLabel extends JLabel{
	/**
	 * Default constructor
	 * @param zLev Zoom-level for the map
	 * @param loc Location to mark and focus on
	 */
	public GMapLabel(int zLev, String loc) {
		URL oUrl = null;
		String pLoc = loc.replace(' ', '+');
		try {
			pLoc = URLEncoder.encode(pLoc, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String oStr = "http://maps.google.com/maps/api/staticmap?center="+pLoc+
					"&zoom="+zLev+"&size=300x300&maptype=roadmap&markers=color:green|"+pLoc+
					"&sensor=false&key=ABQIAAAAjYpsALiVF_AUUh-omeUlkRTNulCFvK6iCeDOYFRIkdMWkijBJhRypShCD9xdl3rd20DwNJyHu7am4w";
		
		try {
			oUrl = new URL(oStr);
		} catch(MalformedURLException malU) {
			System.out.println(malU);
		}
		ImageIcon img = new ImageIcon(oUrl);
		setIcon(img);
	}
}